---
description: "Reference for Nitric's v0 .NET library - Returns a reference to the latest version of a secret, regardless of that version's ID."
---

# .NET - Secret.Latest()

Returns a reference to the `latest` version of a secret, regardless of that version's ID.

```csharp
using Nitric.Sdk;
using Nitric.Sdk.Resource;

var keyRef = Nitric.Secret("apiKey").With(SecretPermission.Accessing);

var latestVersion = keyRef.Latest();

Nitric.Run();
```

## Notes

`Latest()` is most useful when you always want the most recent secret values from the secrets manager. Database credentials and API keys are good examples of secrets where the latest value is usually what you want.

For symmetric encryption, you'll need to retrieve the version of the secret used to _encrypt_ a value when you try to _decrypt_ it again. In those cases `Latest()` isn't a good choice, use [version()](./secret-version) instead.

## Examples

### Get a reference to the latest secret version

```csharp
using Nitric.Sdk;
using Nitric.Sdk.Resource;

var keyRef = Nitric.Secret("apiKey").With(SecretPermission.Accessing);

var latestVersion = keyRef.Latest();

Nitric.Run();
```

### Access the latest value of a secret

```csharp
using Nitric.Sdk;
using Nitric.Sdk.Resource;

var keyRef = Nitric.Secret("apiKey").With(SecretPermission.Accessing);

var latestVersion = keyRef.Latest().Access();

Nitric.Run();
```

<Note>
  See [secret.Version().Access()](./secret-version-access) for more details.
</Note>
